#include<iostream>

using namespace std;
const int N=2e5+10;
int n;
int fa[N];

void init()
{
	for(int i=1;i<=n;i++)
	{
		fa[i]=i;
	}
}

int find(int x)
{
	return x==fa[x]?x:fa[x]=find(fa[x]);
}

void un(int x,int y)
{

	int fx=find(x);
	int fy=find(y);
	fa[fx]=fy;
}

bool issame(int x,int y)
{
	return find(x)==find(y);
}

int main()
{
	int m;cin>>n>>m;
	init();
	while(m--)
	{
		int z,x,y;cin>>z>>x>>y;

		switch(z)
		{
		case 1:
			un(x,y);
			break;
		case 2:
			if(issame(x,y))
			{
				cout<<"Y"<<endl;
			}
			else
			{
				cout<<"N"<<endl;
			}
			break;
		default:
			break;
		}
	}
}